package com.xxr.mom.ci.charging.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xxr.mom.ci.charging.interworking.dto.InterworkingConfigDto;
import com.xxr.mom.ci.charging.interworking.entity.InterworkingConfig;
import com.xxr.mom.ci.charging.interworking.entity.InterworkingNameMapping;
import com.xxr.mom.ci.charging.mapper.charging.InterworkingConfigMapper;
import com.xxr.mom.ci.charging.mapper.charging.InterworkingNameMappingMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * @description: InterworkingConfigService
 * @date: 2024/8/4 0:36
 * @author: natsuki_kining
 * @version: 1.0
 */
@Service
public class InterworkingConfigService {

    @Autowired
    private InterworkingConfigMapper interworkingConfigMapper;

    @Autowired
    private InterworkingNameMappingMapper interworkingNameMappingMapper;

    public InterworkingConfigDto getConfigDto(String operatorId) {
        InterworkingConfigDto dto = new InterworkingConfigDto();
        LambdaQueryWrapper<InterworkingConfig> configLambdaQueryWrapper = new LambdaQueryWrapper<>();
        configLambdaQueryWrapper.eq(InterworkingConfig::getOperatorId, operatorId);
        InterworkingConfig interworkingConfig = interworkingConfigMapper.selectOne(configLambdaQueryWrapper);
        if (Objects.isNull(interworkingConfig)) {
            return null;
        }
        LambdaQueryWrapper<InterworkingNameMapping> interworkingNameMappingQueryWrapper = new LambdaQueryWrapper<>();
        interworkingNameMappingQueryWrapper.eq(InterworkingNameMapping::getConfigId, interworkingConfig.getId());
        List<InterworkingNameMapping> interworkingNameMappingList = interworkingNameMappingMapper.selectList(interworkingNameMappingQueryWrapper);
        dto.setInterworkingConfig(interworkingConfig);
        dto.setNameMappingList(interworkingNameMappingList);
        return dto;
    }

}
